package kr.hkit.androidcomplete01.ch16;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

public class Popup extends Activity {
	private PopupWindow popup;
	private View popupview;
	private LinearLayout linear;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_popup);
		
		linear = (LinearLayout) findViewById(R.id.linear);
		popupview = View.inflate(this, R.layout.ch16_popupview, null);
		popup = new PopupWindow(popupview, 200, 150, true);
		
		final Button btnshow = (Button) findViewById(R.id.btnshow);
		btnshow.setOnClickListener(new Button.OnClickListener(){

			@Override
			public void onClick(View v) {
				//지정한 좌표
				popup.showAtLocation(linear, Gravity.NO_GRAVITY, 100, 150);
				
				//가운데 놓기
			//	popup.showAtLocation(linear, Gravity.CENTER, 0, 0);
				
				//가운데 +50, 80에 놓기
			//	popup.showAtLocation(linear, Gravity.CENTER, 50, 80);
				
				//화면 벗어나기
			//	popup.showAtLocation(linear, Gravity.NO_GRAVITY, 800, 1200);
				
				//수평 중앙, 수직 바닥
			//	popup.showAtLocation(linear, Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 0,0);
				
				//수평중앙, 수직 바닥 (50,50)
			//	popup.showAtLocation(linear, Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM, 50,50);
				
				//버튼 아래에 놓기
/*				popup.setAnimationStyle(-1);
				popup.showAsDropDown(btnshow);*/
			}
		});
	}
}
